package com.sunsun_china.www.aq;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.widget.ImageButton;

/**
 * Created by zhaowujt on 2015/2/27.
 */
public class SwitchImageButton extends ImageButton {
	// 选择状态
	private boolean mSelect = false;
	// 选择资源
	private Drawable mSelectDrawable = null;
	// 未选择资源
	private Drawable mUnSelectDrawable = null;

	public SwitchImageButton(Context context, AttributeSet attrs) {
		super(context, attrs);
		try {
			TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SwitchImageButton);
			mSelect = a.getBoolean(R.styleable.SwitchImageButton_selectState, false);
			mSelectDrawable = a.getDrawable(R.styleable.SwitchImageButton_selectSrc);
			mUnSelectDrawable = a.getDrawable(R.styleable.SwitchImageButton_unSelectSrc);
			this.setSelectState(mSelect);
		} catch (Exception e) {
		}
	}

	public void setSelectState(boolean value) {
		mSelect = value;
		if (mSelect) {
			if (mSelectDrawable != null) {
				super.setImageDrawable(mSelectDrawable);
			}
		} else {
			if (mUnSelectDrawable != null) {
				super.setImageDrawable(mUnSelectDrawable);
			}
		}
	}

	public boolean getSelectState() {
		return mSelect;
	}
}
